//
//  MLSelectBingFaCell.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/24.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "MLSelectBingFaCell.h"
#import "MLButton.h"
#import "BingFaZhengDTO.h"

@interface MLSelectBingFaCell ()

@property (nonatomic, strong) NSMutableArray *indexpathArray;

@end

@implementation MLSelectBingFaCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    [self addSubview:self.smlButton];
    
    [self.smlButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.mas_centerY);
        make.right.mas_equalTo(-20);
        make.size.mas_equalTo(CGSizeMake(70, 30));
        
    }];
}


-(void)setBingfaDto:(BingFaZhengDTO *)bingfaDto{
    _bingfaDto = bingfaDto;

    self.textLabel.text  = bingfaDto.name;
    
}


#pragma mark  - Actions
- (void)clickSmlButton:(UIButton *)smlBtn{
    
    //第一步，设置模型里的选择属性 为 yes
    self.bingfaDto.isSelected = !self.bingfaDto.isSelected;
    
    //第二步：回调刷新
    if (self.clickBingFaZhengCellBlock) {
        self.clickBingFaZhengCellBlock(self.indexpath);
    }
}

#pragma mark  - Lazy
- (UIButton *)smlButton{
    
    if (_smlButton == nil) {
        _smlButton = [[UIButton alloc] init];
        
        [_smlButton setTitle:@"订阅" forState:UIControlStateNormal];

        [_smlButton setTitleColor:RED_COLOR forState:UIControlStateSelected];
        
        [_smlButton addTarget:self action:@selector(clickSmlButton:) forControlEvents:UIControlEventTouchUpInside];
        [_smlButton setBackgroundImage:[UIImage imageNamed:@"nav"] forState:UIControlStateNormal];
        _smlButton.layer.cornerRadius = 3;
        _smlButton.layer.masksToBounds = YES;
    }
    return _smlButton;
}

-(NSMutableArray *)indexpathArray{
    
    if (_indexpathArray == nil) {
        _indexpathArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _indexpathArray;
}

@end
